package com.greendao.gen;

import java.util.List;
import android.database.Cursor;
import android.database.sqlite.SQLiteStatement;

import org.greenrobot.greendao.AbstractDao;
import org.greenrobot.greendao.Property;
import org.greenrobot.greendao.internal.DaoConfig;
import org.greenrobot.greendao.database.Database;
import org.greenrobot.greendao.database.DatabaseStatement;
import org.greenrobot.greendao.query.Query;
import org.greenrobot.greendao.query.QueryBuilder;

import com.yizisu.music.and.roomdblibrary.bean.SongWithAlbum;

import com.yizisu.music.and.roomdblibrary.bean.AlbumInfoTable;

// THIS CODE IS GENERATED BY greenDAO, DO NOT EDIT.
/** 
 * DAO for table "album_info".
*/
public class AlbumInfoTableDao extends AbstractDao<AlbumInfoTable, Long> {

    public static final String TABLENAME = "album_info";

    /**
     * Properties of entity AlbumInfoTable.<br/>
     * Can be used for QueryBuilder and for referencing column names.
     */
    public static class Properties {
        public final static Property DbId = new Property(0, Long.class, "dbId", true, "_id");
        public final static Property Id = new Property(1, String.class, "id", false, "ID");
        public final static Property Source = new Property(2, Integer.class, "source", false, "SOURCE");
        public final static Property Type = new Property(3, Integer.class, "type", false, "TYPE");
        public final static Property FilePath = new Property(4, String.class, "filePath", false, "FILE_PATH");
        public final static Property UrlPath = new Property(5, String.class, "urlPath", false, "URL_PATH");
        public final static Property Title = new Property(6, String.class, "title", false, "TITLE");
        public final static Property Des = new Property(7, String.class, "des", false, "DES");
        public final static Property CreateTime = new Property(8, Long.class, "createTime", false, "CREATE_TIME");
        public final static Property UpdateTime = new Property(9, Long.class, "updateTime", false, "UPDATE_TIME");
    }

    private DaoSession daoSession;

    private Query<AlbumInfoTable> songInfoTable_AlbumInfoTablesQuery;

    public AlbumInfoTableDao(DaoConfig config) {
        super(config);
    }
    
    public AlbumInfoTableDao(DaoConfig config, DaoSession daoSession) {
        super(config, daoSession);
        this.daoSession = daoSession;
    }

    /** Creates the underlying database table. */
    public static void createTable(Database db, boolean ifNotExists) {
        String constraint = ifNotExists? "IF NOT EXISTS ": "";
        db.execSQL("CREATE TABLE " + constraint + "\"album_info\" (" + //
                "\"_id\" INTEGER PRIMARY KEY AUTOINCREMENT ," + // 0: dbId
                "\"ID\" TEXT," + // 1: id
                "\"SOURCE\" INTEGER," + // 2: source
                "\"TYPE\" INTEGER," + // 3: type
                "\"FILE_PATH\" TEXT," + // 4: filePath
                "\"URL_PATH\" TEXT," + // 5: urlPath
                "\"TITLE\" TEXT," + // 6: title
                "\"DES\" TEXT," + // 7: des
                "\"CREATE_TIME\" INTEGER," + // 8: createTime
                "\"UPDATE_TIME\" INTEGER);"); // 9: updateTime
        // Add Indexes
        db.execSQL("CREATE INDEX " + constraint + "IDX_album_info_ID ON \"album_info\"" +
                " (\"ID\" ASC);");
    }

    /** Drops the underlying database table. */
    public static void dropTable(Database db, boolean ifExists) {
        String sql = "DROP TABLE " + (ifExists ? "IF EXISTS " : "") + "\"album_info\"";
        db.execSQL(sql);
    }

    @Override
    protected final void bindValues(DatabaseStatement stmt, AlbumInfoTable entity) {
        stmt.clearBindings();
 
        Long dbId = entity.getDbId();
        if (dbId != null) {
            stmt.bindLong(1, dbId);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(2, id);
        }
 
        Integer source = entity.getSource();
        if (source != null) {
            stmt.bindLong(3, source);
        }
 
        Integer type = entity.getType();
        if (type != null) {
            stmt.bindLong(4, type);
        }
 
        String filePath = entity.getFilePath();
        if (filePath != null) {
            stmt.bindString(5, filePath);
        }
 
        String urlPath = entity.getUrlPath();
        if (urlPath != null) {
            stmt.bindString(6, urlPath);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(7, title);
        }
 
        String des = entity.getDes();
        if (des != null) {
            stmt.bindString(8, des);
        }
 
        Long createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(9, createTime);
        }
 
        Long updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindLong(10, updateTime);
        }
    }

    @Override
    protected final void bindValues(SQLiteStatement stmt, AlbumInfoTable entity) {
        stmt.clearBindings();
 
        Long dbId = entity.getDbId();
        if (dbId != null) {
            stmt.bindLong(1, dbId);
        }
 
        String id = entity.getId();
        if (id != null) {
            stmt.bindString(2, id);
        }
 
        Integer source = entity.getSource();
        if (source != null) {
            stmt.bindLong(3, source);
        }
 
        Integer type = entity.getType();
        if (type != null) {
            stmt.bindLong(4, type);
        }
 
        String filePath = entity.getFilePath();
        if (filePath != null) {
            stmt.bindString(5, filePath);
        }
 
        String urlPath = entity.getUrlPath();
        if (urlPath != null) {
            stmt.bindString(6, urlPath);
        }
 
        String title = entity.getTitle();
        if (title != null) {
            stmt.bindString(7, title);
        }
 
        String des = entity.getDes();
        if (des != null) {
            stmt.bindString(8, des);
        }
 
        Long createTime = entity.getCreateTime();
        if (createTime != null) {
            stmt.bindLong(9, createTime);
        }
 
        Long updateTime = entity.getUpdateTime();
        if (updateTime != null) {
            stmt.bindLong(10, updateTime);
        }
    }

    @Override
    protected final void attachEntity(AlbumInfoTable entity) {
        super.attachEntity(entity);
        entity.__setDaoSession(daoSession);
    }

    @Override
    public Long readKey(Cursor cursor, int offset) {
        return cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0);
    }    

    @Override
    public AlbumInfoTable readEntity(Cursor cursor, int offset) {
        AlbumInfoTable entity = new AlbumInfoTable( //
            cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0), // dbId
            cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1), // id
            cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2), // source
            cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3), // type
            cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4), // filePath
            cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5), // urlPath
            cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6), // title
            cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7), // des
            cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8), // createTime
            cursor.isNull(offset + 9) ? null : cursor.getLong(offset + 9) // updateTime
        );
        return entity;
    }
     
    @Override
    public void readEntity(Cursor cursor, AlbumInfoTable entity, int offset) {
        entity.setDbId(cursor.isNull(offset + 0) ? null : cursor.getLong(offset + 0));
        entity.setId(cursor.isNull(offset + 1) ? null : cursor.getString(offset + 1));
        entity.setSource(cursor.isNull(offset + 2) ? null : cursor.getInt(offset + 2));
        entity.setType(cursor.isNull(offset + 3) ? null : cursor.getInt(offset + 3));
        entity.setFilePath(cursor.isNull(offset + 4) ? null : cursor.getString(offset + 4));
        entity.setUrlPath(cursor.isNull(offset + 5) ? null : cursor.getString(offset + 5));
        entity.setTitle(cursor.isNull(offset + 6) ? null : cursor.getString(offset + 6));
        entity.setDes(cursor.isNull(offset + 7) ? null : cursor.getString(offset + 7));
        entity.setCreateTime(cursor.isNull(offset + 8) ? null : cursor.getLong(offset + 8));
        entity.setUpdateTime(cursor.isNull(offset + 9) ? null : cursor.getLong(offset + 9));
     }
    
    @Override
    protected final Long updateKeyAfterInsert(AlbumInfoTable entity, long rowId) {
        entity.setDbId(rowId);
        return rowId;
    }
    
    @Override
    public Long getKey(AlbumInfoTable entity) {
        if(entity != null) {
            return entity.getDbId();
        } else {
            return null;
        }
    }

    @Override
    public boolean hasKey(AlbumInfoTable entity) {
        return entity.getDbId() != null;
    }

    @Override
    protected final boolean isEntityUpdateable() {
        return true;
    }
    
    /** Internal query to resolve the "albumInfoTables" to-many relationship of SongInfoTable. */
    public List<AlbumInfoTable> _querySongInfoTable_AlbumInfoTables(Long songId) {
        synchronized (this) {
            if (songInfoTable_AlbumInfoTablesQuery == null) {
                QueryBuilder<AlbumInfoTable> queryBuilder = queryBuilder();
                queryBuilder.join(SongWithAlbum.class, SongWithAlbumDao.Properties.AlbumId)
                    .where(SongWithAlbumDao.Properties.SongId.eq(songId));
                songInfoTable_AlbumInfoTablesQuery = queryBuilder.build();
            }
        }
        Query<AlbumInfoTable> query = songInfoTable_AlbumInfoTablesQuery.forCurrentThread();
        query.setParameter(0, songId);
        return query.list();
    }

}
